import { createRouter, createWebHistory } from 'vue-router'
import { combinedRouterGuard } from '@/router/guard'
import { getDeviceType } from '@/utils/device'

import pcRoutes from './pc.routes'
import mobileRoutes from './mobile.routes'
// 将PC和移动端路由合并到主路由数组
const routes = [
  // 根路由重定向，将在守卫中处理
  {
    path: '/',
    redirect: '/pc', // 默认重定向，实际会被守卫重写
  },
  // 登录路由，不带设备前缀
  {
    path: '/login',
    redirect: (to) => `/${getDeviceType()}/login`,
  },
  // 将PC和移动端路由添加到主路由数组
  ...pcRoutes,
  ...mobileRoutes,
]

const router = createRouter({
  history: createWebHistory(),
  routes,
})

router.beforeEach(combinedRouterGuard)

export { router }
